#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

static void printTid(const char* name,const pthread_t &tid)
{
    cout<<name<<" 正在运行 "<<tid<<"  "<<endl;
}

void* Routine(void* argv)
{
    const char* name = static_cast<const char*>(argv);
    int cnt = 5;
    while(true)
    {
        printTid(name,pthread_self());
        if(!(cnt--))
        {
            break;
        }
        sleep(1);
    }
    cout<<"线程退出"<<endl;
    pthread_exit((void*)11111);
}

int main()
{
    pthread_t tid;
    int n = pthread_create(&tid,nullptr,Routine,(void*)"thread");
    void* ret = nullptr;
    pthread_join(tid,&ret);
    cout<<"main pthread success   "<<(long long)ret<<endl;
    sleep(5);
    while(true)
    {
        printTid("main othread",pthread_self());
        sleep(2);
    }
    return 0;
}